﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Manager;
using Model;
using ExtAspNet;
namespace HealthSystem
{
    public partial class SchoolSignAdmin : BasePage
    {
        HW_School_UserManager manager = new HW_School_UserManager();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindGrid();
            }
        }
        public void BindGrid()
        {
            string schoolcode = Request["schoolcode"] as string;
            try
            {
                IList<HW_School_User> list = manager.GetBySchoolCode(schoolcode);
                foreach (HW_School_User user in list)
                {
                    if (user.ErrorTimes > 10)
                    {
                        user.state = false;
                    }
                    else
                    {
                        user.state = true;
                    }
                }
                Gird1.DataSource = list;
                Gird1.DataBind();
            }
            catch
            {
                ExtAspNet.Alert.Show("数据出错");
            }

        }
       
        public void Window1_Close(object sender, EventArgs e)
        {
            BindGrid();
        }
        protected void Row_click(object sender, ExtAspNet.GridCommandEventArgs e)
        {
            try
            {
                string username = Gird1.Rows[e.RowIndex].DataKeys[0] as string;
                if (e.CommandName == "Ulock")
                {
                    HW_School_User user = manager.GetById(username);
                    user.ErrorTimes = 0;
                    manager.ModHW_School_User(user);
                    BindGrid();
                    ExtAspNet.Alert.Show("更新状态成功");
                }
                if (e.CommandName == "reset")
                {
                    string pass = System.Configuration.ConfigurationManager.AppSettings["default"].ToString();
                    int n = manager.ResetPassWord(username, pass);
                    if (n == 1)
                        Alert.Show("密码重置成功");
                    else
                        Alert.Show("密码出错!");
                }
                if (e.CommandName == "delete")
                {
                    manager.DeleteById(username);
                    Alert.Show("删除成功");
                    BindGrid();
                }
            }
            catch
            {
                ExtAspNet.Alert.Show("更新状态出错");
            }
        }
        protected void new_click(object sender, EventArgs e)
        {
            string url = "schooladmin_new.aspx?schoolcode=" + Request["schoolcode"] as string;
            ExtAspNet.PageContext.RegisterStartupScript(Window1.GetShowReference(url,"新增学校管理员"));
        }
    }
}